<template>
  <a-spin :spinning="confirmLoading">
    <div class="container DeviceInformationDetail">
      <div class="auto">
        <div class="pub_tit det_bar clearfix wow fadeInDown animated" data-wow-delay="0.1s">
          <em class="bt">设备详情</em>
          <!-- <div class="crumb fl">
            <a href="#">设备信息</a> > <span>设备详情</span>
          </div> -->
          <a-icon style="float: left; margin-top: 16px; margin-right: 8px; cursor: pointer" type="rollback" @click="goBack"/>
        </div>
        <a-row style="margin-bottom: 16px;">
          <span class="det_bt wow fadeInLeftBig animated" data-wow-delay="0.1s">{{deviceDetail.name}}</span>
          <a-button style="float: right; margin-left: 10px;" @click="handleDelete" v-if="isShowBtnPersson()">删除</a-button>
          <a-button style="float: right" type="primary" @click="editDevice" v-if="isShowBtnPersson()">编辑</a-button>
        </a-row>
        <div class="equip_det">
          <div class="equip_top clearfix">
            <div class="slide fl wow fadeInLeft animated" data-wow-delay="0.1s">
              <div class="hd">
                <ul></ul>
              </div>
              <div class="bd">
                <a-carousel autoplay arrows>
                  <div
                    slot="prevArrow"
                    class="custom-slick-arrow"
                    style="left: 10px;zIndex: 1"
                  >
                    <a-icon type="left-circle" />
                  </div>
                  <div slot="nextArrow" class="custom-slick-arrow" style="right: 10px">
                    <a-icon type="right-circle" />
                  </div>
                  <div v-for="item in imgUrlList" :key="item">
                    <a-col :span="24">
                      <img :src="item" :alt="item" style="width: 100%; height: 316px;">
                    </a-col>
                  </div>
                </a-carousel>
              </div>
            </div>
            <div class="info wow fadeInRight animated" data-wow-delay="0.1s">
              <h6 class="title">{{deviceDetail.name}}</h6>
              <div class="box">
                <h6 class="t_tit">简介</h6>
                <div class="txt clamp" style="overflow:auto;">{{deviceDetail.describe}}</div>
              </div>
            </div>
          </div>
          <div class="equip_use">
            <div class="bar wow fadeInDown animated" data-wow-delay="0.1s">
              <span class="bt">设备使用记录</span>
              <div class="fr" v-if="isRender">
                <a-button
                  @click="batchDel"
                  style="margin-right: 5px;"
                  v-show="selectedRowKeys.length > 0"
                  ghost
                  type="primary"
                  icon="delete">批量删除</a-button>
                <a-upload name="uploadFile" accept=".xlsx" :showUploadList="false" :multiple="false" :headers="tokenHeader1" :action="importExcelUrl" @change="handleImportExcel">
                  <a-button type="primary" icon="import">导入</a-button>
                </a-upload>
                <a-button type="primary" style="margin-left: 5px;" @click="downModel">模板下载</a-button>
              </div>
            </div>
            <div>
              <a-table
                ref="table"
                size="middle"
                bordered
                rowKey="id"
                :columns="columns"
                :dataSource="dataSource"
                :pagination="ipagination"
                :loading="loading"
                @change="handleTableChange"
                :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}">
                <span slot="action" slot-scope="text, record">
                  <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete2(record)">
                    <a style="color: #1890ff">删除</a>
                  </a-popconfirm>
                </span>
              </a-table>
            </div>
        
          </div>
          
        </div>
      </div>
    </div>
  </a-spin>
</template>

<script>
import Vue from 'vue'
import { USER_INFO, ACCESS_TOKEN } from  "@/store/mutation-types"
import '../../../public/css/style.css'
import { getAction, postAction  } from '@/api/manage'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import BASE_URL from '../../../config'
import { isShowBtn } from "@/utils/authFilter"
export default {
  name: 'DeviceInformationDetail',
  mixins: [JeecgListMixin],
  beforeRouteEnter (to, from, next) {
    window.scrollTo(0, 0);
    next();
  },
  data() {
    return {
      tokenHeader1: {
        'token': Vue.ls.get(ACCESS_TOKEN),
        'equipmentId': this.$route.query.deviceId
      },
      confirmLoading: false,
      isRender: false,
      deviceDetail: {},
      imgUrlList: [],
      columns: [
        {
          title: '申请时间',
          align: "center",
          sorter: true,
          dataIndex: 'createDate'
        },
        {
          title: '申请编号',
          align: "center",
          sorter: true,
          dataIndex: 'number'
        },
        {
          title: '实验室',
          align: "center",
          sorter: true,
          dataIndex: 'lab'
        },
        {
          title: '硕士、博士',
          align: "center",
          sorter: true,
          dataIndex: 'name'
        },
        {
          title: '试验项目',
          align: "center",
          sorter: true,
          dataIndex: 'item'
        },
        {
          title: '导师',
          align: "center",
          sorter: true,
          dataIndex: 'mentor'
        },
        {
          title: '状态',
          align: "center",
          sorter: true,
          dataIndex: 'state'
        },
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align: "center",
        //   scopedSlots: {customRender: 'action'},
        // }
      ],
      queryParam: {
        equipmentids: this.$route.query.deviceId
      },
      disableMixinCreated: true,
      url: {
        list: '/equipmentRecord/list',
        delete: '/equipmentRecord/delete',
        deleteBatch: '/equipmentRecord/delete',
        importExcelUrl: '/equipmentRecord/readExcel'
      },
    }
  },
  created() {
    if(Vue.ls.get(USER_INFO) && Vue.ls.get(USER_INFO).username && Vue.ls.get(USER_INFO).role == '1') {
      this.isRender = true
      this.columns.push(
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'},
        }
      )
    } else {
      this.isRender = false
    }
    this.queryParam.id = this.$route.query.deviceId
    this.searchQuery()
    this.getDeviceDetail()
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`;
    },
  },
  methods: {
    isShowBtnPersson() {
      return isShowBtn()
    },
    handleDelete2(record) {
      if(!this.url.delete){
        this.$message.error("请设置url.delete属性!")
        return
      }
      var that = this;
      let param = {
        ids: record.id
      }
      postAction(that.url.delete, param).then((res) => {
        if (res.code == 0) {
          that.$message.success(res.msg);
          that.loadData();
        } else {
          that.$message.warning(res.msg);
        }
      });
    },
    goBack() {
      this.$router.go(-1)
    },
    getDeviceDetail() {
      let self = this
      this.confirmLoading = true
      let url = '/equipment/info/' + this.$route.query.deviceId
      getAction(url, {}).then(res => {
        if(res.code == 0) {
          self.deviceDetail = Object.assign({}, res.result)
          if(res.result.imgurl) {
            self.imgUrlList = res.result.imgurl.split(',')
          }
        } else {
          self.$message.error(res.msg)
        }
      }).finally(() => {
        self.confirmLoading = false
      })
    },
    handleDelete() {
      let self = this
      this.$confirm({
        title: '确认要删除此设备信息?',
        onOk() {
          postAction('/equipment/delete', {ids: self.$route.query.deviceId}).then(res => {
            if(res.code == 0) {
              self.$message.success(res.msg)
              self.$router.go(-1)
            } else {
              self.$message.error(res.msg)
            }
          })
        },
        onCancel() {
        }
      })
    },
    editStaff() {
      this.$router.push({path: '/staffAndWorkers/AddStaffAndWorkers', query: {deviceId: this.$route.query.deviceId}})
    },
    downModel() {
      let url = BASE_URL + '/equipmentRecord/dowloadtemplate'
      window.open(url)
    },
    editDevice() {
      this.$router.push({path: '/deviceInformation/addDevice', query: {deviceId: this.$route.query.deviceId}})
    }
  }
};
</script>

<style scoped>
.DeviceInformationDetail {
  cursor: pointer;
}
.ant-carousel >>> .slick-slide {
  text-align: center;
  height: 316px;
  line-height: 160px;
  background: #364d79;
  overflow: hidden;
}

.ant-carousel >>> .custom-slick-arrow {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #fff;
  background-color: rgba(31, 45, 61, 0.11);
  opacity: 0.3;
}
.ant-carousel >>> .custom-slick-arrow:before {
  display: none;
}
.ant-carousel >>> .custom-slick-arrow:hover {
  opacity: 0.5;
}

.ant-carousel >>> .slick-slide h3 {
  color: #fff;
}
.carousel .ellipsis {
  overflow: hidden;
  text-overflow:ellipsis;
  white-space: nowrap;
}
.carousel .title {
  font-size: 23px;
  color: #fff;
  line-height: 30px;
  text-align: center;
}
.carousel .txt {
  font-size: 15px;
  color: #E6E6E6;
  line-height: 28px;
  -webkit-line-clamp: 7;
  height: 196px;
  margin-top: 15px;
}
.carousel .clamp {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  /*-webkit-line-clamp: 3;*/
}
.clamp::-webkit-scrollbar {/*滚动条整体样式*/
  width: 8px;     /*高宽分别对应横竖滚动条的尺寸*/
  /* height: 1px; */
}

.clamp::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
  border-radius: 10px;
  -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
  background: #535353;
}

.clamp::-webkit-scrollbar-track {/*滚动条里面轨道*/
  -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
  border-radius: 10px;
  background: #EDEDED;
}
</style>
